package com.zprmb.udzt.util;

import java.math.BigDecimal;
import java.math.MathContext;
import java.text.DecimalFormat;

import android.text.Editable;


/**
 * 收益计算器
 * @author shenshao
 */

public class VoteCalculator {
	
	public static String bbt_getVoteCalculator(String arg0, Double rate,int mouth){
		DecimalFormat df = new DecimalFormat("######0.00");   
		double a =Double.valueOf(arg0.toString());
		double b = rate;
		double c = a*b/365d;
		double d = c/100d*mouth;
		return df.format(d)+"";
	}
	
	public static double getVoteCalculator_newuser(String arg0, Double rate,int mouth){
		double a =Double.valueOf(arg0.toString());
		double b = rate;
		double c = a*b/365;
		double d = c/100d*mouth;
		return d;
	}
	
	
	public static String getVoteCalculator(String arg0, Double rate,int mouth){
		DecimalFormat df = new DecimalFormat("######0.00"); 
		double a =Double.valueOf(arg0.toString());
		double b = rate;
		double c = a*b/365;
		double d = c/100d*mouth;
		return df.format(d)+"";
	}
	
	public static String getVoteCalculator(Editable arg0,int rate,int mouth){
		DecimalFormat df = new DecimalFormat("######0.00");   
		double a =Double.valueOf(arg0.toString());
		double b = rate/100d;
		double c = a*b/360d;
		double d = c/100d*mouth;
		return df.format(d)+"";
	}
	public static String getNatviecVoteCalculator(Editable arg0,int mouth){
		DecimalFormat df = new DecimalFormat("######0.00");   
		double a =Double.valueOf(arg0.toString());
		double b = 0.35;
		double c = a*b/360d;
		double d = c/100d*mouth;
		return df.format(d)+"";
	}
	//等额本金
	public static String matchingprincipal( Double amount,Double rate,int month){
		DecimalFormat df = new DecimalFormat("######0.00");   
		double a=month+1;
		double b=a*amount;
		double c=rate/100d/12;
		double d=b*c/2;
//		（还款月数+1）×贷款额×月利率/2
		return df.format(d);
		
	}
	//等额本息
	public static String equalprincipalandinterest(BigDecimal amount,BigDecimal monthRate,int totalMonths){
		 System.out.println(amount.toString()+"...."+monthRate.toString());
		 BigDecimal monthReturn = amount.multiply(monthRate)
               .multiply(monthRate.add(new BigDecimal("1")).pow(totalMonths))
               .divide(monthRate.add(new BigDecimal("1")).pow(totalMonths).subtract(new BigDecimal("1")), MathContext.DECIMAL128);
       //总利息
//		 System.out.println(monthReturn.toString());
		 BigDecimal   interest = monthReturn.multiply(new BigDecimal(totalMonths)).subtract(amount, MathContext.DECIMAL128).setScale(2, BigDecimal.ROUND_HALF_DOWN);
		return interest.toString();
		
	}
	
	public static String getBeiShuVoteCalculator(int rate){
		double a = rate/35;
		return a+"";
	}
	 public static double getVoteCalculator_month(String arg0, Double rate,int mouth){
			double a =Double.valueOf(arg0.toString());
			double b = rate;
			double c = a*b/365;
			double d = c/100d*mouth;
			return d;
		}
	 public static double getVoteCalculator_month_Dou(Double arg0, Double rate,int mouth){
			double a =arg0;
			double b = rate;
			double c = a*b/365;
			double d = c/100d*mouth;
			return d;
		}
	/**
	 * 优选的计算器   mouth  这里是天数    上面的也是天数  
	 */
	public static String getUplanVoteCalculator(Editable arg0,int rate,int mouth){
		DecimalFormat df = new DecimalFormat("######0.00");   
		double a =Double.valueOf(arg0.toString());
		double b = rate/100d;
		double c = a*b/365d;
		double d = c/100d*mouth;
		return df.format(d)+"";
	}
}
